﻿using System;
using System.Device.Location;
using Com.PhilChuang.Utils;
using GeoCoordinate = Com.PhilChuang.Mobile.Apps.LocationSender.Model.Data.GeoCoordinate;

namespace Com.PhilChuang.Mobile.Apps.LocationSender.Utils
{
	public static class LocationSenderWp7Extensions
	{
		public static GeoCoordinate ToAppGeoCoordinate (this GeoPosition<System.Device.Location.GeoCoordinate> self)
		{
			self.ThrowIfNull ("self");
			var gc = new GeoCoordinate {
			                           	Altitude = self.Location.Altitude,
			                           	Course = self.Location.Course,
			                           	HorizontalAccuracy = self.Location.HorizontalAccuracy,
			                           	IsUnknown = self.Location.IsUnknown,
			                           	Latitude = self.Location.Latitude,
			                           	Longitude = self.Location.Longitude,
			                           	Speed = self.Location.Speed,
			                           	VerticalAccuracy = self.Location.VerticalAccuracy,
			                           	Timestamp = self.Timestamp.ToLocalTime ().DateTime,
			                           };
			return gc;
		}

		public static System.Device.Location.GeoCoordinate ToWp7GeoCoordinate (this GeoCoordinate self)
		{
			self.ThrowIfNull ("self");
			if (self.IsUnknown) return System.Device.Location.GeoCoordinate.Unknown;
			var gc = new System.Device.Location.GeoCoordinate {
			                                                  	Altitude = self.Altitude,
			                                                  	Course = self.Course,
			                                                  	HorizontalAccuracy = self.HorizontalAccuracy,
			                                                  	Latitude = self.Latitude,
			                                                  	Longitude = self.Longitude,
			                                                  	Speed = self.Speed,
			                                                  	VerticalAccuracy = self.VerticalAccuracy,
			                                                  };
			return gc;
		}
	}
}
